<template>
	<view class="">
		<view class="cont_top flex justify-between">
			<view class="flex">
				<image v-if="!userCont.company_logo" class="cont_img" src="/static/img2/home/empty_logo.jpg" mode="aspectFit"></image>
				<image v-else class="cont_img" :src="userCont.company_logo" mode="aspectFit"></image>
				<view>
					<view class="cont_t font-weight-bold h4">{{ userCont.company_name || '' }}</view>
					<view class="tag_list flex justify-between font_24 my-2">
						<text v-for="(item, index) of userCont.label_str" :key="index" class="c_9 p">{{ item }}</text>
					</view>
				</view>
			</view>
			<view class="cont_head_r flex" v-if="isIcon">
				<view class="mr-2" @click="ewmChange" v-if="userCont.is_code == 1">
					<image src="@/static/img2/home/c_ewm.png" mode="scaleToFill" style="border-radius: 0;width: 39rpx;height: 39rpx;margin-top: 5rpx;"></image>
				</view>
				<view class="mr-1 text-center" @click="collectionChange">
					<image v-if="userCont.qiyeYsc <= 0" src="/static/img2/nav1/collection0.png" mode=""></image>
					<image v-else src="/static/img2/nav1/collection1.png" mode="aspectFill"></image>
					<text class="c_9 font_24">{{ userCont.qiyeShouCang }}</text>
				</view>
				<view class="hand_good text-center" @click="goodChange">
					<image v-if="userCont.qiyeYdz <= 0" src="/static/img2/nav1/fabulous0.png" mode=""></image>
					<view v-else>
						<text v-if="userCont.addanimal" class="add1 h6 c_main font-weight-bolder">+1</text>
						<image src="/static/img2/nav1/fabulous1.png" mode="aspectFill"></image>
					</view>
					<text class="c_9 font_24">{{ userCont.qiyeDianZan }}</text>
				</view>
			</view>
		</view>
		<!-- <view class="desc my-2 font-sm c_9 flex justify-between align-center font_24_2" v-if="userCont.company_desc" style="z-index: 999;">
			<text class="desc_text text_hidden2">{{ userCont.company_desc }}</text>
			<text class="text-right" @click="detailShow = true">详情></text>
			<u-modal :show="detailShow" title="企业详情" confirmText="关闭" closeOnClickOverlay @close="detailShow = false" @confirm="detailShow = false" style="z-index: 999;">
				<view class="slot-content w-100">
					<scroll-view scroll-y="true">
						<view class="u-content" style="max-height: 700rpx;">
							<view v-if="!userCont.company_content" class="p-2 mt-3"><u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty></view>
							<view class="text" v-else><u-parse :content="userCont.company_content"></u-parse></view>
						</view>
					</scroll-view>
				</view>
			</u-modal>
		</view> -->
	</view>
</template>

<script>
import { likecollectionDzsc } from '@/api/home/company.js';
export default {
	props: ['companyUser', 'isIcon'],
	data() {
		return {
			userCont: {}
		};
	},
	created() {
		// console.log(this.companyUser);
		this.userCont = this.companyUser;
	},
	watch: {
		userCont: {
			handler(newV, oldV) {
				// console.log('userCont', newV);
				this.$emit('userChange', newV);
			},
			deep: true,
			immediate: true
		}
	},
	methods: {
		// 收藏
		collectionChange() {
			let isDz = this.userCont.qiyeYsc == 0 ? 1 : 2;
			this.dzscChange(1, isDz);
		},
		// 点赞
		goodChange() {
			let isSc = this.userCont.qiyeYdz == 0 ? 1 : 2;
			this.dzscChange(2, isSc);
		},
		dzscChange(type, status) {
			if (!uni.getStorageSync('userInfo').hasLogin) {
				this.toLogin(); // 未登录
			} else {
				let msg = {
					checktype: 2, //执行收藏点赞企业操作
					type: type, //1 收藏企业  2  点赞企业  3 收藏产品  4 点赞产品
					status: status, // 1 收藏以及点赞企业、产品  2 取消收藏以及点赞 企业、产品
					company_product_id: this.userCont.id, // 传递对应企业以及产品id
					uid: uni.getStorageSync('userInfo').userId //用户id
				};
				likecollectionDzsc(msg)
					.then(res => {
						if (res.code == 0) {
							uni.$u.toast(res.msg);
							let sc = parseInt(this.userCont.qiyeShouCang),
								dz = parseInt(this.userCont.qiyeDianZan);
							if (type == 1) {
								// 处理收藏企业后的操作
								var add = sc + 1;
								var minus = sc == 0 ? sc : sc - 1;
								this.userCont.qiyeYsc = this.userCont.qiyeYsc <= 0 ? 1 : 0;
								this.userCont.qiyeShouCang = status == 1 ? add : minus;
							} else {
								// 处理点赞企业后的操作
								var add = dz + 1;
								var minus = dz - 1;
								this.userCont.qiyeYdz = this.userCont.qiyeYdz <= 0 ? 1 : 0;
								this.userCont.qiyeDianZan = status == 1 ? add : minus;
								this.userCont.addanimal = true;
							}
						} else {
							uni.$u.toast(res.msg);
						}
					})
					.catch(err => {
						console.log('点赞或收藏失败', err);
						uni.$u.toast('点赞或收藏失败');
					});
			}
		},
		ewmChange() {
			this.$emit('ewmChange');
		}
	}
};
</script>

<style lang="scss" scoped>
.cont_img {
	margin-right: 15rpx;
	width: 100rpx;
	height: 100rpx;
	border-radius: 15rpx;
	border: 1px solid #f2f2f2;
}

.tag_list {
	text {
		background-color: #f2f2f2;
		border-radius: 12rpx;
	}
}

.cont_head_r {
	image {
		width: 44rpx;
		height: 44rpx;
	}
	.hand_good {
		position: relative;
		.add1 {
			position: absolute;
			top: 0rpx;
			left: 0;
			z-index: 999;
			opacity: 0;
			animation: mygood 3s linear 0s 1 normal running;
		}
		@keyframes mygood {
			0% {
				top: -10rpx;
				opacity: 0.5;
			}
			50% {
				top: -50rpx;
				opacity: 1;
			}
			100% {
				top: -60rpx;
				opacity: 0;
			}
		}
	}
}
</style>
